#include "clientcontext.h"
#include <iostream>
#ifdef _WINDOWS_
#include <Windows.h>
#elif defined(_LINUX_)
#include "../common/atomic.h"
#endif

CClientContext::CClientContext(boost::asio::io_service& ios)
	: m_sock(ios)
{
	m_nRef = 1;
	m_vctrecv.reserve(2048);
	
	std::cout << "new CClientContext: " << (long)this << std::endl;
}

CClientContext::~CClientContext()
{
	std::cout << "free CClientContext: " << (long)this << std::endl;
}

void CClientContext::AddRef()
{
	InterlockedIncrement(&m_nRef);
}

void CClientContext::Release()
{
	if(InterlockedDecrement(&m_nRef) <= 0)
	{
		delete this;
	}
}

bool CClientContext::GetContext(ClientContext cc, void* p)
{
	return false;
}

bool CClientContext::Send(unsigned char* pSend, int nLen)
{
	return false;
}

CClientContext* CClientContext::CreateClient(boost::asio::io_service& ios)
{
	return new CClientContext(ios);
}
